<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>vue2.0一起在懵逼的海洋里越陷越深（二） | leenty blog</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="本文章系列：vue2.0一起在懵逼的海洋里越陷越深 (http://leenty.com/tags/vuejs/) 说好了一起懵逼，那么我们继续下沉在上一篇里已经将vue2.0需要的依赖都装齐了那么接下来因为vue最后生成的页面看似静态页面(对于静态页面这里有些偷鸡用法，不管你怎样，反正我已经露出了诡异的微笑😏，再贴一个vue2.0 demo的项目地址，大爷有兴趣可进去看看演示，开心了就加个星)">
<meta name="keywords" content="vuejs,vue-router">
<meta property="og:type" content="article">
<meta property="og:title" content="vue2.0一起在懵逼的海洋里越陷越深（二）">
<meta property="og:url" content="http://baidu.com/2016/11/20/vue2-2/index.html">
<meta property="og:site_name" content="leenty blog">
<meta property="og:description" content="本文章系列：vue2.0一起在懵逼的海洋里越陷越深 (http://leenty.com/tags/vuejs/) 说好了一起懵逼，那么我们继续下沉在上一篇里已经将vue2.0需要的依赖都装齐了那么接下来因为vue最后生成的页面看似静态页面(对于静态页面这里有些偷鸡用法，不管你怎样，反正我已经露出了诡异的微笑😏，再贴一个vue2.0 demo的项目地址，大爷有兴趣可进去看看演示，开心了就加个星)">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://baidu.com/img/vue/vue2-2.png">
<meta property="og:image" content="http://baidu.com/img/vue/files-tree.png">
<meta property="og:image" content="http://baidu.com/img/vue/router-main.js.png">
<meta property="og:image" content="http://baidu.com/img/vue/files-tree.png">
<meta property="og:updated_time" content="2019-09-02T05:49:38.263Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="vue2.0一起在懵逼的海洋里越陷越深（二）">
<meta name="twitter:description" content="本文章系列：vue2.0一起在懵逼的海洋里越陷越深 (http://leenty.com/tags/vuejs/) 说好了一起懵逼，那么我们继续下沉在上一篇里已经将vue2.0需要的依赖都装齐了那么接下来因为vue最后生成的页面看似静态页面(对于静态页面这里有些偷鸡用法，不管你怎样，反正我已经露出了诡异的微笑😏，再贴一个vue2.0 demo的项目地址，大爷有兴趣可进去看看演示，开心了就加个星)">
<meta name="twitter:image" content="http://baidu.com/img/vue/vue2-2.png">
  
    <link rel="alternative" href="/atom.xml" title="leenty blog" type="application/atom+xml">
  
  
    <link rel="icon" href="//favicon.png">
  
  <script src="/style.js"></script>
  

  
<!-- baidu_tongji -->
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?5bae4c35e53fde3bf2526312c3edaf1d";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>
<!-- End baidu_tongji -->


</head>
</html>
<body>
  <div id="container">
    <div class="left-col">
      <div class="overlay"></div>
<div class="intrude-less">
	<header id="header" class="inner">
		<a href="/" class="profilepic">
			
			<img src="/img/default_avatar.png" class="js-avatar">
			
		</a>

		<hgroup>
		  <h1 class="header-author"><a href="/">leenty</a></h1>
		</hgroup>

		

		<nav class="header-menu">
			<ul>
			
				<li><a href="/">主页</a></li>
	        
				<li><a href="/archives">所有文章</a></li>
	        
			</ul>
		</nav>
		<nav class="header-smart-menu">
	        
    		
    			
    			<a class="js-smart-menu" data-idx="0" href="javascript:void(0)">所有文章</a>
    			
    			
            
    			
    			<a class="js-smart-menu" data-idx="1" href="javascript:void(0)">标签</a>
    			
    			
            
    			
    			<a class="js-smart-menu" data-idx="2" href="javascript:void(0)">友链</a>
    			
    			
            
    			
    			<a class="js-smart-menu" data-idx="3" href="javascript:void(0)">关于我</a>
    			
    			
            
		</nav>
		<nav class="header-nav">
			<div class="social">
				
					<a class="github" target="_blank" href="https://github.com/leenty" title="github">github</a>
		        
			</div>
		</nav>
	</header>		
</div>

    </div>
    <div class="mid-col">
      <nav id="mobile-nav">
  	<div class="overlay">
  		<div class="slider-trigger"><i class="icon-list"></i></div>
  		<h1 class="header-author js-mobile-header hide">leenty</h1>
  	</div>
	<div class="intrude-less">
		<header id="header" class="inner">
			<div class="profilepic">
				
					<img src="/img/default_avatar.png" class="js-avatar">
				
			</div>
			<hgroup>
			  <h1 class="header-author">leenty</h1>
			</hgroup>
			
			<nav class="header-menu">
				<ul>
				
					<li><a href="/">主页</a></li>
		        
					<li><a href="/archives">所有文章</a></li>
		        
				</ul>
			</nav>
			<nav class="header-nav">
				<div class="social">
					
						<a class="github" target="_blank" href="https://github.com/leenty" title="github">github</a>
			        
				</div>
			</nav>
		</header>				
	</div>
</nav>

      <div class="body-wrap">
        <article id="post-vue2-2" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      vue2.0一起在懵逼的海洋里越陷越深（二）
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>本文章系列：<a href="http://leenty.com/tags/vuejs/" target="_blank" rel="noopener">vue2.0一起在懵逼的海洋里越陷越深 (http://leenty.com/tags/vuejs/)</a></p>
<h3 id="说好了一起懵逼，那么我们继续下沉"><a href="#说好了一起懵逼，那么我们继续下沉" class="headerlink" title="说好了一起懵逼，那么我们继续下沉"></a>说好了一起懵逼，那么我们继续下沉</h3><p>在上一篇里已经将vue2.0需要的依赖都装齐了<br>那么接下来<br><img src="/img/vue/vue2-2.png" alt="vue2.0"><br>因为vue最后生成的页面看似静态页面(对于静态页面这里有些偷鸡用法，不管你怎样，反正我已经露出了诡异的微笑😏，再贴一个<a href="https://github.com/leenty/vue2" target="_blank" rel="noopener">vue2.0 demo的项目地址</a>，大爷有兴趣可进去看看演示，开心了就加个星)，其实却是个SPA(单页面应用)<br>没错！就是一个SPA</p>
<h3 id="作为一个SPA，当然有不同的地方"><a href="#作为一个SPA，当然有不同的地方" class="headerlink" title="作为一个SPA，当然有不同的地方"></a>作为一个SPA，当然有不同的地方</h3><p>SPA与传统网页区别的地方是SPA具有前端路由来模拟页面跳转，当然这是众多不同之一，这篇只说前端路由。<br>上一篇中有安装vue-router组件，这个就是vue的前端路由<br>vue + vue-router简直是爽，页面跳转的速度简直是不要不要的<br>不光是用户体验上的提升，作为一名开发者，在使用了如vue，react等这类MVVM框架后，就不会再想回到jQuery的时代了。</p>
<h3 id="前面搞了半天，现在要开始coding啦！"><a href="#前面搞了半天，现在要开始coding啦！" class="headerlink" title="前面搞了半天，现在要开始coding啦！"></a>前面搞了半天，现在要开始coding啦！</h3><p>好的，用自己的小编辑器打开vue项目（我用的是sublime）<br>可以看到项目目录是这样子的<br><img src="/img/vue/files-tree.png" alt="files-tree"><br>(插一句，如果喜欢这个sublime主题可以<a href="http://leenty.com/2016/10/06/sublime-material-theme/" target="_blank" rel="noopener">查看这篇文章</a>)<br>与自己的目录对比发现少几个文件，那是没有什么关系的，接下来要做的就是去创建这些文件。</p>
<h3 id="作为一个SPA，首先要有路由"><a href="#作为一个SPA，首先要有路由" class="headerlink" title="作为一个SPA，首先要有路由"></a>作为一个SPA，首先要有路由</h3><p>从目录图片里可以看到<code>main.js</code>这个文件，没错这个就是程序的入口<br>这个文件的内容是这样的<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> Vue <span class="keyword">from</span> <span class="string">'vue'</span></span><br><span class="line"><span class="keyword">import</span> router <span class="keyword">from</span> <span class="string">'./router'</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> App <span class="keyword">from</span> <span class="string">'./App'</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/* eslint-disable no-new */</span></span><br><span class="line"><span class="keyword">new</span> Vue(&#123;</span><br><span class="line">  router,</span><br><span class="line">  render: <span class="function"><span class="params">h</span> =&gt;</span> h(App)</span><br><span class="line">&#125;).$mount(<span class="string">'#app'</span>)</span><br></pre></td></tr></table></figure></p>
<p><a href="https://github.com/leenty/vue2/blob/master/src/main.js" target="_blank" rel="noopener"><code>main.js</code>地址</a><br>这里用的是ES6的语法，使用<code>import</code>来导入包<br>这里导入了vue包，还有两个文件，分别是<code>router.js</code>和<code>App.vue</code><br><code>.js</code>后缀是可以省略的(毕竟是亲生的，你不说导入什么类型的文件，肯定是自家人毕竟亲呀)<br>其实<code>.vue</code>后缀也是可以省略的，我建议还是写一下，如果遇到两个同名文件就尴尬了。</p>
<p>好的，这个<code>router.js</code>就是路由的输出口啦，<br><code>App.vue</code>就是目录里已经存在的那个模板文件啦，你的界面就从这里开始啦。<br>引入了包就可以开始设置路由和挂载模板了</p>
<p>顺带一提，可以看到在<code>new Vue()</code>时传入了一个对象，但是这个对象却不是键值对，<br>是这样，这是ES6的一种语法，当引用的变量名和键名相同时，就可以简写成这样<br>如果还原来是这样的<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">new</span> Vue(&#123;</span><br><span class="line">  router: router,</span><br><span class="line">  render: <span class="function"><span class="params">h</span> =&gt;</span> h(App)</span><br><span class="line">&#125;).$mount(<span class="string">'app'</span>)</span><br><span class="line"><span class="comment">// 被简写成了</span></span><br><span class="line"><span class="keyword">new</span> Vue(&#123;</span><br><span class="line">  router, <span class="comment">// 这是ES6对象的简写，扩展开就是router: router</span></span><br><span class="line">  <span class="comment">// 箭头函数(=&gt;)是ES6的新语法</span></span><br><span class="line">  render: <span class="function"><span class="params">h</span> =&gt;</span> h(App) <span class="comment">// 这里扩展开就是render: (h) =&gt; &#123; return h(App) &#125;</span></span><br><span class="line">&#125;).$mount(<span class="string">'app'</span>)</span><br></pre></td></tr></table></figure></p>
<p>PS：ES6的新语法现在网上文章已经有很多了，我之后也会发一版常用的语法</p>
<h3 id="那么现在在src目录下创建router-js文件"><a href="#那么现在在src目录下创建router-js文件" class="headerlink" title="那么现在在src目录下创建router.js文件"></a>那么现在在src目录下创建<code>router.js</code>文件</h3><p>内容是这样的：<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> Vue <span class="keyword">from</span> <span class="string">'vue'</span></span><br><span class="line"><span class="keyword">import</span> VueRouter <span class="keyword">from</span> <span class="string">'vue-router'</span></span><br><span class="line"><span class="keyword">import</span> routes <span class="keyword">from</span> <span class="string">'./routes'</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 告诉vue要使用router</span></span><br><span class="line">Vue.use(VueRouter)</span><br><span class="line"></span><br><span class="line"><span class="comment">/* eslint-disable no-new */</span></span><br><span class="line"><span class="comment">// 实例化router对象</span></span><br><span class="line"><span class="keyword">const</span> router = <span class="keyword">new</span> VueRouter(&#123;</span><br><span class="line">  mode: <span class="string">'hash'</span>, <span class="comment">// 设置路由模式 可选值: "hash" | "history" | "abstract"，默认"hash"</span></span><br><span class="line">  linkActiveClass: <span class="string">'u-link--Active'</span>, <span class="comment">// 这是链接激活时的class</span></span><br><span class="line">  <span class="comment">// base: '/app/', // 这个是设置根目录路径，一般用不到，默认'/'</span></span><br><span class="line">  routes <span class="comment">// 挂载路由集合 后面会说</span></span><br><span class="line">&#125;)</span><br><span class="line"><span class="comment">// 导出router对象</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> router</span><br></pre></td></tr></table></figure></p>
<p><a href="https://github.com/leenty/vue2/blob/master/src/router.js" target="_blank" rel="noopener">这是<code>router.js</code>地址</a><br>这里引入了两个包<code>vue</code>,<code>vue-router</code>和一个包含路由集合的<code>routes.js</code>文件<br>整个文件的逻辑就是，使用<code>Vue.use()</code>方法告诉vue我们使用了路由<br>然后就大大方方的导出路由对象<br><img src="/img/vue/router-main.js.png" alt="main.js router"><br>这个时候<code>main.js</code>里就可以接受到这里导出的路由对象，并挂载到vue对象上</p>
<h3 id="在src目录下创建routes-js文件"><a href="#在src目录下创建routes-js文件" class="headerlink" title="在src目录下创建routes.js文件"></a>在src目录下创建<code>routes.js</code>文件</h3><p><code>routes.js</code>是用来放置路由集合的文件<br>其实路由集合是可以写在<code>router.js</code>里的，这里为什么不写在一起呢？<br>因为当路由集合变得庞大时，如果还是写在<code>router.js</code>里，就会显得拥挤，不便于阅读<br>所以这里推荐单独写出来。<br>同时呢也可以创建路由所对应的模板文件(<code>.vue</code>文件，我把它称为模板文件)，<code>Article.vue</code>和<code>Home.vue</code><br>模板文件叫什么名由自己决定，于是就能看到这张图里所有文件都齐了<br><img src="/img/vue/files-tree.png" alt="files-tree"></p>
<p>那么在编写<code>routes.js</code>文件之前，需要先写好两个模板的内容(不然一会有没有成功都不清楚了，23333)</p>
<p>好的，贴一下<code>home.vue</code>的内容<br><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">template</span> <span class="attr">lang</span>=<span class="string">"pug"</span>&gt;</span></span><br><span class="line">.home</span><br><span class="line">  h1.l-ta--c Material Desgin</span><br><span class="line"><span class="tag">&lt;/<span class="name">template</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="javascript">  <span class="keyword">export</span> <span class="keyword">default</span> &#123;</span></span><br><span class="line">    data () &#123;</span><br><span class="line"><span class="javascript">      <span class="keyword">return</span> &#123;</span></span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">style</span> <span class="attr">lang</span>=<span class="string">"stylus"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br></pre></td></tr></table></figure></p>
<p>vue模板是html结构的，这也是对界面编写最友好的方式<br>里面的<code>&lt;template&gt; &lt;/template&gt;</code>标签就是视图<br><code>&lt;script&gt;&lt;/script&gt;</code>就是js，这个没有争议<br><code>&lt;style&gt;&lt;/style&gt;</code>是写css的，这个也没有问题<br>但是当仔细看我的代码，发现里面html使用了pug，css使用了stylus<br>其实不用他们也是可行的，只是用pug和stylus写结构比较清晰<br>不用也可以的<br>如果要使用，请打开你的终端，给项目添加几个包<br><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm i pug stylus stylus-loader -D</span><br></pre></td></tr></table></figure></p>
<p>里面的css的class(<code>.l-ta--c</code>)看着有点懵逼的，可以看看<a href="http://www.leenty.com/2016/11/06/css/#main" target="_blank" rel="noopener">使用BEM+emmet的css书写与命名技巧</a><br>好的，模板不需要太复杂，只要有字能显示就好了，至于<code>Article.vue</code>也是一样的，这里就不贴了</p>
<p>Tips：模板里推荐有一个根元素，就像这里的<code>.home</code>就是根元素，这样不容易混乱，结构会清晰</p>
<h3 id="写好了模板就可以开始编写routes-js了"><a href="#写好了模板就可以开始编写routes-js了" class="headerlink" title="写好了模板就可以开始编写routes.js了"></a>写好了模板就可以开始编写<code>routes.js</code>了</h3><p>先贴代码!<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 导入之前写好的两个模板</span></span><br><span class="line"><span class="keyword">import</span> Home <span class="keyword">from</span> <span class="string">'./components/Home.vue'</span></span><br><span class="line"><span class="keyword">import</span> Article <span class="keyword">from</span> <span class="string">'./components/Article.vue'</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 编写路由集合</span></span><br><span class="line"><span class="keyword">const</span> routes = [</span><br><span class="line">  &#123;</span><br><span class="line">    name: <span class="string">'Home'</span>, <span class="comment">// 路由名，这个字段是可选的</span></span><br><span class="line">    path: <span class="string">'/'</span>, <span class="comment">// 路由路径，这里是根路径所以是'/'</span></span><br><span class="line">    component: Home <span class="comment">// 模板</span></span><br><span class="line">  &#125;, <span class="comment">// 这些是常用的</span></span><br><span class="line">  &#123;</span><br><span class="line">    name: <span class="string">'Article'</span>,</span><br><span class="line">    path: <span class="string">'/article'</span>,</span><br><span class="line">    component: Article</span><br><span class="line">  &#125;</span><br><span class="line">]</span><br><span class="line"><span class="comment">// 导出路由集合</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> routes</span><br></pre></td></tr></table></figure></p>
<p><a href="https://github.com/leenty/vue2/blob/master/src/routes.js" target="_blank" rel="noopener">然后是文件地址</a><br>最后导出了路由集合(<code>routes</code>)后就可以在<code>router.js</code>里使用了<br>于是，前面的<code>router.js</code>里的<code>routes</code>就有了。</p>
<h3 id="现在进行最后一步，到App-vue里添加路由"><a href="#现在进行最后一步，到App-vue里添加路由" class="headerlink" title="现在进行最后一步，到App.vue里添加路由"></a>现在进行最后一步，到<code>App.vue</code>里添加路由</h3><p>代码如下：<br><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">template</span> <span class="attr">lang</span>=<span class="string">"pug"</span>&gt;</span></span><br><span class="line">  .app</span><br><span class="line">    header</span><br><span class="line">      //- 制作一个跳转链接</span><br><span class="line">      //- 这里不要直接用a链接跳转，那样会导致页面重载，</span><br><span class="line">      //- 相比之下用router-link是高效的方案</span><br><span class="line">      //- to属性就是链接的地址啦</span><br><span class="line">      router-link(to="/") home</span><br><span class="line">      router-link(to="/article") article</span><br><span class="line">    bodyer</span><br><span class="line">      //- 路由地址所对应的模板将会被挂载到router-view标签上</span><br><span class="line">      router-view</span><br><span class="line"><span class="tag">&lt;/<span class="name">template</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="javascript">  <span class="keyword">export</span> <span class="keyword">default</span> &#123;</span></span><br><span class="line">    data () &#123;</span><br><span class="line"><span class="javascript">      <span class="keyword">return</span> &#123;</span></span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">style</span> <span class="attr">lang</span>=<span class="string">"stylus"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br></pre></td></tr></table></figure></p>
<p><a href="https://github.com/leenty/vue2/blob/master/src/App.vue" target="_blank" rel="noopener">地址</a><br>好了，到此为止就完成了路由搭建与使用了。</p>

      
    </div>
    <div class="article-info article-info-index">
      
      <a href="/2016/11/20/vue2-2/" class="archive-article-date">
  	<time datetime="2016-11-20T15:41:16.000Z" itemprop="datePublished"><i class="icon-clock"></i>2016-11-20</time>
</a>
      
	<div class="article-tag tagcloud">
		<i class="icon-price-tags"></i>
		<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/vue-router/">vue-router</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/vuejs/">vuejs</a></li></ul>
	</div>

      

      <div class="clearfix"></div>
    </div>
  </div>
</article>

  
<nav id="article-nav">
  
    <a href="/2016/11/27/vue2-3/" id="article-nav-newer" class="article-nav-link-wrap">
      <i class="icon-circle-left"></i>
      <div class="article-nav-title">
        
          vue2.0一起在懵逼的海洋里越陷越深（三）
        
      </div>
    </a>
  
  
    <a href="/2016/11/16/interesting_button_by_css/" id="article-nav-older" class="article-nav-link-wrap">
      <div class="article-nav-title">使用纯css制作有炫酷交互的按钮</div>
      <i class="icon-circle-right"></i>
    </a>
  
</nav>




<div class="share_jia">
	<!-- JiaThis Button BEGIN -->
	<div class="jiathis_style">
		<span class="jiathis_txt">Share to: &nbsp; </span>
		<a class="jiathis_button_facebook"></a> 
	    <a class="jiathis_button_twitter"></a>
	    <a class="jiathis_button_plus"></a> 
	    <a class="jiathis_button_tsina"></a>
		<a class="jiathis_button_cqq"></a>
		<a class="jiathis_button_douban"></a>
		<a class="jiathis_button_weixin"></a>
		<a class="jiathis_button_tumblr"></a>
    <a href="http://www.jiathis.com/share" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	</div>
	<script type="text/javascript" src="//v3.jiathis.com/code/jia.js?uid=1405949716054953" charset="utf-8"></script>
	<!-- JiaThis Button END -->
</div>






<div class="duoshuo">
	<!-- 多说评论框 start -->
	<div class="ds-thread" data-thread-key="vue2-2" data-title="vue2.0一起在懵逼的海洋里越陷越深（二）" data-url="http://baidu.com/2016/11/20/vue2-2/"></div>
	<!-- 多说评论框 end -->
	<!-- 多说公共JS代码 start (一个网页只需插入一次) -->
	<script type="text/javascript">
	var duoshuoQuery = {short_name:"leenty-blog"};
	(function() {
		var ds = document.createElement('script');
		ds.type = 'text/javascript';ds.async = true;
		ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
		ds.charset = 'UTF-8';
		(document.getElementsByTagName('head')[0] 
		 || document.getElementsByTagName('body')[0]).appendChild(ds);
	})();
	</script>
	<!-- 多说公共JS代码 end -->
</div>





      </div>
      <footer id="footer">
  <div class="outer">
    <div id="footer-info">
    	<div class="footer-left">
    		&copy; 2019 leenty
    	</div>
      	<div class="footer-right">
      		<a href="http://hexo.io/" target="_blank">Hexo</a>  Theme <a href="https://github.com/litten/hexo-theme-yilia" target="_blank">Yilia</a> by Litten
      	</div>
    </div>
  </div>
</footer>
    </div>
    <script>
	var yiliaConfig = {
		fancybox: true,
		mathjax: false,
		animate: true,
		isHome: false,
		isPost: true,
		isArchive: false,
		isTag: false,
		isCategory: false,
		open_in_new: false,
		root: "/",
		innerArchive: true
	}
</script>

<script src="/./main.js"></script>


    
<div class="tools-col">
  <ul class="btn-wrap">
    
      <li class="chose" data-hook="tools-section-all"><span class="text">全部</span><i class="icon-book"></i></li>
    
    
      <li data-hook="tools-section-tag"><span class="text">标签</span><i class="icon-price-tags"></i></li>
    
    
      <li data-hook="tools-section-friends"><span class="text">友链</span><i class="icon-link"></i></li>
    
    
      <li data-hook="tools-section-me"><span class="text">我</span><i class="icon-smile"></i></li>
    
  </ul>
  <div class="tools-wrap">
    
    	<section class="tools-section tools-section-all chose">
    	</section>
    

    
    	<section class="tools-section tools-section-tag">
    			<div class="widget tagcloud" id="js-tagcloud">
    				<a href="/tags/ES6/" style="font-size: 10px;">ES6</a> <a href="/tags/css/" style="font-size: 15px;">css</a> <a href="/tags/git/" style="font-size: 10px;">git</a> <a href="/tags/github/" style="font-size: 10px;">github</a> <a href="/tags/gulp/" style="font-size: 10px;">gulp</a> <a href="/tags/hexo/" style="font-size: 12.5px;">hexo</a> <a href="/tags/js/" style="font-size: 12.5px;">js</a> <a href="/tags/other/" style="font-size: 10px;">other</a> <a href="/tags/sublime/" style="font-size: 10px;">sublime</a> <a href="/tags/vim/" style="font-size: 10px;">vim</a> <a href="/tags/vue-router/" style="font-size: 17.5px;">vue-router</a> <a href="/tags/vuejs/" style="font-size: 20px;">vuejs</a> <a href="/tags/vuex/" style="font-size: 12.5px;">vuex</a>
    			</div>
    	</section>
    

    
    	<section class="tools-section tools-section-friends">
  		
  			<div class="friends-wrap" id="js-friends">
  			
  	          <a target="_blank" class="main-nav-link switch-friends-link" href="http://vue2.leenty.com">vue2.0演示地址</a>
  	        
  	          <a target="_blank" class="main-nav-link switch-friends-link" href="http://www.leenty.com/">leenty的博客</a>
  	        
  	          <a target="_blank" class="main-nav-link switch-friends-link" href="https://whqet.github.io/">whqet的博客</a>
  	        
  	          <a target="_blank" class="main-nav-link switch-friends-link" href="https://shenyubin.github.io/">沈雨彬的博客</a>
  	        
  	          <a target="_blank" class="main-nav-link switch-friends-link" href="http://www.deboy.cn">Deboy的博客</a>
  	        
  	        </div>
  		
    	</section>
    

    
    	<section class="tools-section tools-section-me">
  	  	
  	  		<div class="aboutme-wrap" id="js-aboutme">不会捣(xia)鼓(gao)的前端不是好全栈</div>
  	  	
    	</section>
    
  </div>
  
</div>
    <!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                      <div class="pswp__preloader__cut">
                        <div class="pswp__preloader__donut"></div>
                      </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div> 
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>
  </div>
</body>
</html>